package com.tsy.imageloader;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends AppCompatActivity {

    private ImageView ivDemo;
    private SimpleDraweeView simpleDraweeView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ivDemo = findViewById(R.id.iv_demo);
        simpleDraweeView = findViewById(R.id.sdv_pic);
        simpleDraweeView.setImageURI("https://preview.shejiku123.com/thumbnail/10109/1000/1036583.jpg");
//        ivDemo.setImageResource(R.drawable.fish);
        Glide.with(this).load(R.drawable.fish)
//                .placeholder() placeholder 是默认的加载图片 即网络图片没有加载成功时，所显示的图片
//                .error() 网络图片加载失败时，显示的图片
//                .fallback() 图片加载后 的回调方法
                .into(new CustomTarget<Drawable>() {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        //如果图片原始宽高过于大，可以通过图片压缩工具（比如鲁班压缩：https://github.com/Curzibn/Luban）来进行压缩
                        //获取图片原始高度
                        int height = resource.getIntrinsicHeight();
                        //获取图片原始宽度
                        int width = resource.getIntrinsicWidth();
                        Log.i("imageSize","height"+height+",width"+width);
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {

                    }
                });
    }
}